# -*- encoding:utf-8 -*-

from django.forms import ModelForm, TextInput

class CKWidget(TextInput):
    def render(self,name,value,attrs=None):
        sp=super(CKWidget,self).render(name,value,attrs)
        scrpt=u"""<script>
        editor=CKEDITOR.replace('{name}')
        editor.setData('{value}')
        $('form').submit(function( event ) {{
           $('#{id}').val(editor.getData())
        }});
        </script>
        """.format(name=name,value=value,id=attrs.get('id'))
        #print(scrpt)
        return sp+scrpt

class MobileForm(ModelForm):
    class Meta:
        widgets = {
            'long_dsp': CKWidget(attrs={'name': 'long_dsp'})
        }


